Repository navigation
include/stdio.h: Hide the kernel file system types from kernel-build programs. - #20565
Conversation
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s):
CI run: https://github.com/apache/nuttx/actions/runs/37943764063 |
896862b to
c383513
Compare
6b508c0 to
3db73ba
Compare
|
@linguini1 I moved the nxstyle commit, and the tools/nxstyle.c fix it needs, to #20621. When it is merged, this PR keeps only the stdio.h commit. |
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/38248342757 |
|
@casaroli please fix: |
#20565 adds include directives to these files, and the check job runs nxstyle on the whole of every changed file. Their nxstyle errors are older than the change: braces, case labels and comments in the wrong column, missing blank lines after declarations, and long lines. Only the layout changes. With all white space and comment margins removed, every file is identical to the old one, except two: iconv() and stm32_touchscreen.c get braces around one-line statements, and getpass() gets a break aligned. The object code of the three libc files is identical before and after on qemu-armv8a:nsh with LIBC_LOCALE. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
77d0912 to
516eb56
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/38346358795 |
c393b35
c393b35 to
9a38e62
Compare
…programs. stdio.h included nuttx/fs/fs.h and nuttx/lib/lib.h, so every program that includes stdio.h saw the kernel's struct file, struct inode and the other file system types. A program that defines its own struct file does not compile. stdio.h no longer includes nuttx/lib/lib.h in any build, and includes nuttx/fs/fs.h only for kernel code and for flat and protected builds. In the user space of a kernel build (CONFIG_BUILD_KERNEL and not __KERNEL__) programs cannot use the file system types anyway, so they do not see them. Doing the same for flat and protected builds breaks many files that rely on the indirect include. stdio.h now defines what it needs itself: the fopencookie() callback types, struct file_struct and its __FS_FLAG_* flags, which were in nuttx/fs/fs.h, and the declaration of lib_get_stream(), which stdin, stdout and stderr expand to. struct streamlist moves from nuttx/fs/fs.h to nuttx/tls.h, where struct task_info_s holds the stream list. nuttx/tls.h includes stdio.h for struct file_struct. The files that used kernel types or other headers through stdio.h now include what they use. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
9a38e62 to
0c8dcf1
Compare
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): CI run: https://github.com/apache/nuttx/actions/runs/38364521591 |
Summary
stdio.hincludesnuttx/fs/fs.handnuttx/lib/lib.h. So every program that includesstdio.halso sees the kernel'sstruct file,struct inodeand the other file system types. A program that defines its ownstruct filedoes not compile:error: redefinition of 'struct file'.This PR makes
stdio.hstop includingnuttx/lib/lib.hin all builds (review), andnuttx/fs/fs.hin the user space of a kernel build (CONFIG_BUILD_KERNELand not__KERNEL__), where programs cannot use those types. Kernel code, and flat and protected builds, still getfs.h. Removing it for every build breaks many files that rely on the indirect include; that can be a later PR.stdio.hnow defines what it needs itself: thefopencookie()callback types,struct file_structand its__FS_FLAG_*flags, which were innuttx/fs/fs.h, and the declaration oflib_get_stream(), whichstdin,stdoutandstderrexpand to.struct streamlistmoves fromnuttx/fs/fs.htonuttx/tls.h, wherestruct task_info_sholds the stream list.nuttx/tls.hincludesstdio.hforstruct file_struct. Nonuttx/fs/cookie.his needed:stdio.hno longer reachesnuttx/tls.h(the old path wasstdio.h->lib.h->kmalloc.h->sched.h->tls.h).The files that used
lib.h,kmalloc.h,stdlib.horunistd.hnames throughstdio.hnow include what they use (69 files in drivers, arch, boards, fs, sched and libs).The old nxstyle errors of the changed files, and the
tools/nxstyle.cfix they need, were merged in #20621. This PR is now thestdio.hcommit only.Impact
Code that used names from
nuttx/lib/lib.h,nuttx/kmalloc.h,nuttx/sched.h,stdlib.horunistd.hthroughstdio.hmust include those headers itself. This includes 44 apps files, fixed in apache/nuttx-apps#3839. Its description lists them and how they were found: every apps C file compiled against master and against this PR, for four configurations.Testing
A program that defines its own
struct fileand includes<stdio.h>, built outside the tree against theqemu-armv8a:knshexport package and run in QEMU 11:Before:
After:
Builds with
-Wno-cpp -Werrorand apps master. The kernel builds marked (i) also runmake exportand the appsmake import.qemu-armv8a:knsh(i),imx93-evk:knsh,qemu-armv7a:knsh(i),sabre-6quad:netknsh(i),rv-virt:knsh,rv-virt:knetnsh64(i),rv-virt:kfb64,rv-virt:knsh_paging,icicle:knsh,canmv230:knsh,esp32s3-devkit:kernel_n8r2,mps3-an547:knsh.lm3s6965-ek:qemu-flat,lm3s6965-ek:qemu-protected,mps2-an500:nsh,qemu-armv8a:nsh,esp32-devkitc:nsh,esp32-devkitc:adc,rv-virt:nsh64,sabre-6quad:nsh,stm32f4discovery:nsh,spresense:wifi_smp,nucleo-f302r8:ihm07m1_b16,esp32c6-devkitc:mpu60x0,ox64:adc,mikroe-stm32f4:fulldemo,tm4c1294-launchpad:nsh,xmc4800-relax:nsh,icicle:rpmsg-ch2, and 19 more configurations of a sweep chosen for many drivers and apps.esp32c6-devkitc:oa_tc6,qemu-armv7a:full(its libcxx and mbedtls errors are on master too),stm32f746g-disco:dropbear,linum-stm32h753bi:zbus.sama5d4-ek:knsh,sama5d4-ek:nxwm(sam_mck_frequency),sim:nshon macOS.tools/checkpatch.sh -c -u -m -gpasses.depends-on: apache/nuttx-apps/pull/3839